package com.roc.web.action.estrn;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.roc.dao.operator.IPowerInfoDao;
import com.roc.newPage.IPageService;
import com.roc.page.BaseSearchCondition;
import com.roc.page.PaginationBaseAction;
import com.roc.pojo.Operators;
import com.roc.pojo.TblTfrTrnLog;
import com.roc.service.IExcelService;
import com.roc.service.IMerchantServices;
import com.roc.service.ServiceException;
import com.roc.service.operator.IPowerInfoService;
import com.roc.util.Constance;
import com.roc.util.DateUtil;
import com.roc.util.Utils;
import com.roc.util.constant.ConfigProperties;
import com.roc.util.constant.Constant;
import com.roc.util.constant.Role;

/**
 * 
 * @author 陈锴
 * 
 * 交易查询
 * 
 * 2014-08-09
 *
 */

@Component
@Scope("prototype")
@Namespace("/estrnlog")
public class EstrnInfoAction extends PaginationBaseAction{
	
	private Logger logger=LogManager.getLogger(EstrnInfoAction.class);
	private InputStream excelFile;
	
	@Autowired
	IPageService pagenitionService;
	
	@Autowired 
	IMerchantServices merchantServices;
	@Autowired
	IExcelService excelService;
	@Autowired
	private IPowerInfoService powerInfoService;
	
	private EstrnInfoSearchCondition searchCondition;
	
//	protected Map<String,String> tranMap=ConfigProperties.getTransTypes();;
	protected Map<String,String> respondeMap = ConfigProperties.getSysDB1("RESP_CD",false);
//	protected Map<String,String> respMap=ConfigProperties.getRespCodeTypes();
//	protected Map<String,String> allRespMap=ConfigProperties.getRespCodeQueryTypes();
	protected Map<String,String> reversalMap=ConfigProperties.getReversalTypes();
	protected Map<String,String> tranMap = ConfigProperties.getSysDB1("TRANS_CD",false);
	
	@Action(value = "queryEstrnInfoJsp", results = { @Result(name = "success", location = "/pages/estrn/queryEstrn.jsp")
             })
	public String queryEstrnInfoAction() throws Exception{
		
		if(searchCondition==null){
			searchCondition=new EstrnInfoSearchCondition();
		}
		
		searchCondition.setTranDate(Constance.formatDate("yyyyMMdd"));
//		searchCondition.setRespCode("00");//成功
		searchCondition.setMinDate(DateUtil.getDate(new Date(),0,"yyyyMMdd"));
		searchCondition.setMaxDate(DateUtil.getDate(new Date(),0,"yyyyMMdd"));
		org();
//		getSession().setAttribute("allRespMap",allRespMap);
		return SUCCESS;
	}
	
	public void org(){
		HashMap<String , String> newResMap = new LinkedHashMap<String, String>();
		
		Set<Entry<String,String>> entrySet = respondeMap.entrySet();
		Iterator it = entrySet.iterator();
		while(it.hasNext()){
			Entry<String,String> en = (Entry<String, String>) it.next();
			String key = en.getKey();
			String value = en.getValue();
			if(!"00".equals(key)){
				newResMap.put(key, value);
			}else{
				newResMap.put(key, value);
				newResMap.put("9999", "失败");
			}
		}
		
		Iterator tranIt = tranMap.entrySet().iterator();
		while(tranIt.hasNext()){
			Entry<String,String> en = (Entry<String, String>) tranIt.next();
			String key = en.getKey();
			if("1161".equals(key)||"1261".equals(key)||"1361".equals(key)
					||"1461".equals(key)||"1561".equals(key)||"1661".equals(key)){
				tranIt.remove();
			}
		}
		
		getRequest().setAttribute("tranMap",tranMap);
		getRequest().setAttribute("respMap",newResMap);
	}
	
	@Action(value = "queryEstrnList", results = { @Result(name = "success", location = "/pages/estrn/queryEstrn.jsp")
           })
	//查询交易记录
	public String queryEstrnListAction() throws Exception{
		
        Operators logingMerchant=(Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
		try {
			if(searchCondition==null){
				searchCondition=(EstrnInfoSearchCondition)getSearchConditionFromSession();
				if(searchCondition==null){
					searchCondition=new EstrnInfoSearchCondition();
				}
			}
			logger.info("查询条件："+"交易日期："+searchCondition.getMinDate()+"-"+searchCondition.getMaxDate());
			if("".equals(Constance.Null2EmptyTrim(searchCondition.getMinDate())) || "".equals(Constance.Null2EmptyTrim(searchCondition.getMaxDate()))){
				logger.info("交易查询查询条件日期为空。。。");
				return SUCCESS;
			}
			Map<String, String> map=powerInfoService.queryRealIdByOpId(logingMerchant.getSuperiorId(), logingMerchant.getRoleType(), logingMerchant.getId(), logingMerchant.getOrgCode());
           // String orgCode=map.get("orgCode");
            String superRole= map.get("superRole");
            String opRealId =map.get("opRealId");
           // searchCondition.setGroupCd(map.get("groupCd"));
			//当登录人员为代理商时，查询他的子代理
			searchCondition.setRoleType(superRole);
			if(Role.MERCHANT.getCode().equals(superRole)){
				searchCondition.setMerNo(logingMerchant.getAccountNo());
			}else if(Role.AGENT.getCode().equals(superRole)||Role.SFB_AGENT.getCode().equals(superRole)){
				
				String agentId= opRealId;
				searchCondition.setAgentId(agentId);
				
			}else if(Role.AGENT_BUSS.getCode().equals(superRole)){
				searchCondition.setOpId(opRealId);
			}else if(Role.MARKET_DIRECT.getCode().equals(superRole) || Role.MARKET_LEAD.getCode().equals(superRole)){
				searchCondition.setMarketorId(opRealId);
			}else if(Role.O_MANAGER.getCode().equals(superRole)){
				searchCondition.setUcbccdArea(logingMerchant.getOneagentid());
			}/*else if(Role.OPERATORS_COMM.getCode().equals(logingMerchant.getRoleType()) && !Constant.SD_ORG_CD.equals(logingMerchant.getOneagentid())){//运维人员
				searchCondition.setUcbccdArea(logingMerchant.getOneagentid());
			}*/else{
				searchCondition.setOrgCode(logingMerchant.getOrgCode());
			}
			int rows=pagenitionService.countSQL(searchCondition);
			if(rows>0){
				searchRsList=pagenitionService.findAllSQL(searchCondition, calcuStart(getCurrentPage()), Constance.PAGE_MAX_SIZE);
			}
			List<TblTfrTrnLog> tftList = new ArrayList<TblTfrTrnLog>();
			dealTheSearchRsList(tftList,searchRsList);
		
			getRequest().setAttribute("tftList", tftList);
			this.setTotalPage(this.calcuTotalPage(rows));
			getRequest().setAttribute(SEARCH_RS_LIST, searchRsList);
			getRequest().setAttribute(CURRENT_PAGE, this.getCurrentPage());
			getRequest().setAttribute(TOTAOL_PAGE, this.getTotalPage());
			org();
			setSearchToConditionSession(searchCondition);
			addActionMessage("当前条件下统计到【"+rows+"】条记录");
			
		} catch (ServiceException e) {
			e.printStackTrace();
			logger.error(e.getMessage(),e);
			addActionError(e.getMessage());
			
		}
		
		return SUCCESS;
	}
	
	
	private void dealTheSearchRsList(List<TblTfrTrnLog> tftList,
			List<Object> searchRsList) {
		try {
			
		
	    Operators logingMerchant=(Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
//	    Map<String, String> transTypes=ConfigProperties.getTransTypes();
	    
		if(searchRsList!=null&&searchRsList.size()>0){
			Iterator iterator=searchRsList.iterator();
			while (iterator.hasNext()) {
				Object[] obj= (Object[])iterator.next();
				TblTfrTrnLog t = new TblTfrTrnLog();
				//主账号
				if("1".equals(logingMerchant.getAgentType())){
					t.setPriAcctNo(Constance.Null2EmptyTrim(obj[5]));
				}else{
					t.setPriAcctNo(Utils.dealCardNoTwo(Constance.Null2EmptyTrim(obj[5])));
				}
				
				
				//卡BIN
				/*List<Object> cardBinList = ConfigProperties.getCardBin();
				for (int i = 0; i < cardBinList.size(); i++) {
					Object[] objs=(Object[]) cardBinList.get(i);
					if(Constance.Null2EmptyTrim(obj[0]) != null && Constance.Null2EmptyTrim(obj[0]) != ""){
						
						for (int j = 10; j >=2; j--) {
							if(Constance.Null2EmptyTrim(objs[0]).equals(Constance.Null2EmptyTrim(obj[0]).substring(0, j))){
								estrn.setCardName(Constance.Null2EmptyTrim(objs[1]));
								estrn.setBankName(Constance.Null2EmptyTrim(objs[2]));
								break;
							}
						}

					}
				}*/
				
				t.setTransDt(Constance.Null2EmptyTrim(obj[0]));
				t.setTransMt(Constance.Null2EmptyTrim(obj[1]));
				t.setTranTp(Constance.Null2EmptyTrim(obj[2]));
				t.setRespCd(Constance.Null2EmptyTrim(obj[3]));
				t.setTransSt(Constance.Null2EmptyTrim(obj[4]));
				t.setCardType(Constant.CARD_CLASS_MAP.get(Constance.Null2EmptyTrim(obj[6])));
//				t.setTransAt(Constance.Null2EmptyTrim(obj[8]));
				t.setMchntNmConv(Constance.Null2EmptyTrim(obj[9]));
				t.setMchntCd(Constance.Null2EmptyTrim(obj[10]));
				t.setTermId(Constance.Null2EmptyTrim(obj[11]));
				t.setMaTransSeq(Long.parseLong(Constance.Null2EmptyTrim(obj[12])));
				t.setRetriRefNo(Constance.Null2EmptyTrim(obj[13]));
				
				String maTransCd = Constance.Null2EmptyTrim(obj[15]);
				if("1191".equals(maTransCd)||"1291".equals(maTransCd)||"1391".equals(maTransCd)
						||"1491".equals(maTransCd)||"1591".equals(maTransCd)||"1691".equals(maTransCd)){
					t.setRespName(Constance.Null2EmptyTrim(obj[19]));
				}else{
					t.setRespName(respondeMap.get(Constance.Null2EmptyTrim(obj[3])));
				}
				
				
				t.setTransInf(tranMap.get(Constance.Null2EmptyTrim(obj[15])));
				t.setMchntCdConv(Constance.Null2EmptyTrim(obj[17]));
				t.setRetriRefNoConv(Constance.Null2EmptyTrim(obj[18]));
/*				if(Constance.OPERATORS_FLAG_OEM.equals(logingMerchant.getFlag())&&!Role.O_MANAGER.getCode().equals(logingMerchant.getRoleType())){
//					t.setRespName(Utils.dealRespCodeName(respMap.get(Constance.Null2EmptyTrim(obj[3]))));
					t.setRespName(respondeMap.get(Constance.Null2EmptyTrim(obj[3])));
				}else{
//					t.setRespName(Utils.dealRespCodeName(Constance.Null2EmptyTrim(obj[3]),allRespMap));
					t.setRespName(respondeMap.get(Constance.Null2EmptyTrim(obj[3])));
				}*/
				String tra = Constance.Null2EmptyTrim(obj[8]);
				if("".equals(tra)){
					t.setTransAt("0.00");
				}else{
					BigDecimal btra = new BigDecimal(tra);
					BigDecimal bb = new BigDecimal(100);
					BigDecimal bres = btra.divide(bb,2,BigDecimal.ROUND_HALF_UP); 
					t.setTransAt(bres.toString());
				}
				String posEntrymd = Constance.Null2EmptyTrim(obj[14]);
				t.setPosEntryMdCd(posEntrymd);
//				if(posEntrymd.length()<3){
//					t.setPosEntryMdCdName("未知");
//				}else if("02".equals(posEntrymd.substring(0, 2))){
//					t.setPosEntryMdCdName("刷磁");
//				}else if("05".equals(posEntrymd.substring(0, 2))||"07".equals(posEntrymd.substring(0, 2))){
//					t.setPosEntryMdCdName("芯片");
//				}else if("05".equals(posEntrymd.substring(0, 2))||"07".equals(posEntrymd.substring(0, 2))){
//					t.setPosEntryMdCdName("芯片");
//				}
				String cardClass = Constance.Null2EmptyTrim(obj[6]);
				if(posEntrymd.length()<3){
					t.setPosEntryMdCdName("未知");
				}else if("02".equals(posEntrymd.substring(0, 2))){
					t.setPosEntryMdCdName("磁条卡");
				}else if("05".equals(posEntrymd.substring(0, 2))){
					t.setPosEntryMdCdName("芯片插卡");
				}else if("07".equals(posEntrymd.substring(0, 2))){
					if("".equals(cardClass)){
						t.setPosEntryMdCdName("未知");
					}else if("0".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片非接");
					}else if("1".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片云闪付");
					}
				}else if("98".equals(posEntrymd.substring(0, 2))){
					if("".equals(cardClass)){
						t.setPosEntryMdCdName("未知");
					}else if("0".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片非接");
					}else if("1".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片云闪付");
					}
				}

				t.setMaTransCd(Constance.Null2EmptyTrim(obj[15]));
				
				if("1171".equals(t.getMaTransCd())||"1011".equals(t.getMaTransCd())||"4011".equals(t.getMaTransCd())||"2011".equals(t.getMaTransCd())||
				   "1161".equals(t.getMaTransCd())||"1191".equals(t.getMaTransCd())||"1261".equals(t.getMaTransCd())||"1291".equals(t.getMaTransCd())||
				   "1361".equals(t.getMaTransCd())||"1391".equals(t.getMaTransCd())||"1461".equals(t.getMaTransCd())||"1491".equals(t.getMaTransCd())||
				   "1461".equals(t.getMaTransCd())||"1491".equals(t.getMaTransCd())||"1561".equals(t.getMaTransCd())||"1591".equals(t.getMaTransCd())||
				   "1661".equals(t.getMaTransCd())||"1691".equals(t.getMaTransCd())){
					String rs = Utils.dealTransSt(t.getMaTransCd(),t.getTransSt());
					t.setDealRs(rs);
				}
				
				t.setKeyRsp(Constance.Null2EmptyTrim(obj[16]));
				
				tftList.add(t);
			}
		}
		
		} catch (Exception e) {
			logger.error("交易查询List解析异常",e);
			throw new RuntimeException("交易查询List解析异常");
		}
	}

	@Action(value="exportEstrn",results = {@Result(name="success",type="stream"
			,params = { "contentType", "application/vnd.ms-excel", "inputName",  
			            "excelFile","contentDisposition",  "attachment;filename=${excelName}.xlsx",
			            "bufferSize", "1024*3" }),@Result(name="error",location="/pages/estrn/queryEstrn.jsp") }) 
	public String  exportEstrn() throws Exception{
		
			 Operators logingMerchant=(Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
				
				if(searchCondition==null){
					searchCondition=(EstrnInfoSearchCondition)getSearchConditionFromSession();
					if(searchCondition==null){
						searchCondition=new EstrnInfoSearchCondition();
					}
				}
				if("".equals(Constance.Null2EmptyTrim(searchCondition.getMinDate()))){
					logger.info("交易导出查询条件日期为空。。。");
					return "error";
				}
				try {
					Map<String, String> map=powerInfoService.queryRealIdByOpId(logingMerchant.getSuperiorId(), logingMerchant.getRoleType(), logingMerchant.getId(), logingMerchant.getOrgCode());
			           // String orgCode=map.get("orgCode");
			            String superRole= map.get("superRole");
			            String opRealId =map.get("opRealId");
			           // searchCondition.setGroupCd(map.get("groupCd"));
						//当登录人员为代理商时，查询他的子代理
						searchCondition.setRoleType(superRole);
						if(Role.MERCHANT.getCode().equals(superRole)){
							searchCondition.setMerNo(logingMerchant.getAccountNo());
						}else if(Role.AGENT.getCode().equals(superRole)||Role.SFB_AGENT.getCode().equals(superRole)){
							
							String agentId= opRealId;
							searchCondition.setAgentId(agentId);
							
						}else if(Role.AGENT_BUSS.getCode().equals(superRole)){
							searchCondition.setOpId(opRealId);
						}else if(Role.MARKET_DIRECT.getCode().equals(superRole) || Role.MARKET_LEAD.getCode().equals(superRole)){
							searchCondition.setMarketorId(opRealId);
						}else if(Role.O_MANAGER.getCode().equals(superRole)){
							searchCondition.setUcbccdArea(logingMerchant.getOneagentid());
						}/*else if(Role.OPERATORS_COMM.getCode().equals(logingMerchant.getRoleType()) && !Constant.SD_ORG_CD.equals(logingMerchant.getOneagentid())){//运维人员
							searchCondition.setUcbccdArea(logingMerchant.getOneagentid());
						}*/else{
							searchCondition.setOrgCode(logingMerchant.getOrgCode());
						}
					
					int rows=pagenitionService.countSQL(searchCondition);
					if(rows>0){
						searchRsList=pagenitionService.findAllSQL(searchCondition, calcuStart(getCurrentPage()), rows);
					}
					
					List<TblTfrTrnLog> tftList = new ArrayList<TblTfrTrnLog>();
					Map<String,String> resMap = dealTheSearchRsListForExport(tftList,searchRsList);
					
					SXSSFWorkbook  work=excelService.exportTransFlow(tftList,searchCondition.getMinDate(),searchCondition.getMaxDate(),resMap,logingMerchant);

					 ByteArrayOutputStream output = new ByteArrayOutputStream();  
					         work.write(output);  
					   
					        byte[] ba = output.toByteArray();  
					         excelFile = new ByteArrayInputStream(ba);  
					         output.flush();  
					         output.close();  
					
		}catch (ServiceException e) {
			e.printStackTrace();
			logger.error(e.getMessage(),e);
			addActionError(e.getMessage());
			
		}
		
		return SUCCESS;
	}
	
	
	private Map<String,String> dealTheSearchRsListForExport(List<TblTfrTrnLog> tftList,
			List<Object> searchRsList) {
		Map<String,String> resMap = new HashMap<String, String>();
		BigDecimal totalAmt = new BigDecimal(0);
		int totalCount = 0;
		BigDecimal cxTotalAmt = new BigDecimal(0);
		int cxTotalCount = 0;
		try {
	    Operators logingMerchant=(Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
//	    Map<String, String> transTypes=ConfigProperties.getTransTypes();
	    
		if(searchRsList!=null&&searchRsList.size()>0){
			Iterator iterator=searchRsList.iterator();
			while (iterator.hasNext()) {
				Object[] obj= (Object[])iterator.next();
				TblTfrTrnLog t = new TblTfrTrnLog();
				//主账号
				if("1".equals(logingMerchant.getAgentType())){
					t.setPriAcctNo(Constance.Null2EmptyTrim(obj[5]));
				}else{
					t.setPriAcctNo(Utils.dealCardNoTwo(Constance.Null2EmptyTrim(obj[5])));
				}
				
				
				//卡BIN
				/*List<Object> cardBinList = ConfigProperties.getCardBin();
				for (int i = 0; i < cardBinList.size(); i++) {
					Object[] objs=(Object[]) cardBinList.get(i);
					if(Constance.Null2EmptyTrim(obj[0]) != null && Constance.Null2EmptyTrim(obj[0]) != ""){
						
						for (int j = 10; j >=2; j--) {
							if(Constance.Null2EmptyTrim(objs[0]).equals(Constance.Null2EmptyTrim(obj[0]).substring(0, j))){
								estrn.setCardName(Constance.Null2EmptyTrim(objs[1]));
								estrn.setBankName(Constance.Null2EmptyTrim(objs[2]));
								break;
							}
						}

					}
				}*/
				
				t.setTransDt(Constance.Null2EmptyTrim(obj[0]));
				t.setTransMt(Constance.Null2EmptyTrim(obj[1]));
				t.setTranTp(Constance.Null2EmptyTrim(obj[2]));
				t.setRespCd(Constance.Null2EmptyTrim(obj[3]));
				t.setTransSt(Constance.Null2EmptyTrim(obj[4]));
				t.setCardType(Constant.CARD_CLASS_MAP.get(Constance.Null2EmptyTrim(obj[6])));
//				t.setTransAt(Constance.Null2EmptyTrim(obj[8]));
				t.setMchntNmConv(Constance.Null2EmptyTrim(obj[9]));
				t.setMchntCd(Constance.Null2EmptyTrim(obj[10]));
				t.setTermId(Constance.Null2EmptyTrim(obj[11]));
				t.setMaTransSeq(Long.parseLong(Constance.Null2EmptyTrim(obj[12])));
				t.setRetriRefNo(Constance.Null2EmptyTrim(obj[13]));
				
				String maTransCd = Constance.Null2EmptyTrim(obj[15]);
				if("1191".equals(maTransCd)||"1291".equals(maTransCd)||"1391".equals(maTransCd)
						||"1491".equals(maTransCd)||"1591".equals(maTransCd)||"1691".equals(maTransCd)){
					t.setRespName(Constance.Null2EmptyTrim(obj[19]));
				}else{
					t.setRespName(respondeMap.get(Constance.Null2EmptyTrim(obj[3])));
				}
				
				t.setTransInf(tranMap.get(Constance.Null2EmptyTrim(obj[15])));
				t.setMchntCdConv(Constance.Null2EmptyTrim(obj[17]));
				t.setRetriRefNoConv(Constance.Null2EmptyTrim(obj[18]));
/*				if(Constance.OPERATORS_FLAG_OEM.equals(logingMerchant.getFlag())&&!Role.O_MANAGER.getCode().equals(logingMerchant.getRoleType())){
//					t.setRespName(Utils.dealRespCodeName(respMap.get(Constance.Null2EmptyTrim(obj[3]))));
					t.setRespName(respondeMap.get(Constance.Null2EmptyTrim(obj[3])));
				}else{
//					t.setRespName(Utils.dealRespCodeName(Constance.Null2EmptyTrim(obj[3]),allRespMap));
					t.setRespName(respondeMap.get(Constance.Null2EmptyTrim(obj[3])));
				}*/
				String tra = Constance.Null2EmptyTrim(obj[8]);
				if("".equals(tra)){
					t.setTransAt("0.00");
				}else{
					BigDecimal btra = new BigDecimal(tra);
					BigDecimal bb = new BigDecimal(100);
					BigDecimal bres = btra.divide(bb,2,BigDecimal.ROUND_HALF_UP); 
					t.setTransAt(bres.toString());
				}
				String posEntrymd = Constance.Null2EmptyTrim(obj[14]);
				t.setPosEntryMdCd(posEntrymd);
//				if(posEntrymd.length()<3){
//					t.setPosEntryMdCdName("未知");
//				}else if("02".equals(posEntrymd.substring(0, 2))){
//					t.setPosEntryMdCdName("刷磁");
//				}else if("05".equals(posEntrymd.substring(0, 2))||"07".equals(posEntrymd.substring(0, 2))){
//					t.setPosEntryMdCdName("芯片");
//				}else if("05".equals(posEntrymd.substring(0, 2))||"07".equals(posEntrymd.substring(0, 2))){
//					t.setPosEntryMdCdName("芯片");
//				}
				String cardClass = Constance.Null2EmptyTrim(obj[6]);
				if(posEntrymd.length()<3){
					t.setPosEntryMdCdName("未知");
				}else if("02".equals(posEntrymd.substring(0, 2))){
					t.setPosEntryMdCdName("磁条卡");
				}else if("05".equals(posEntrymd.substring(0, 2))){
					t.setPosEntryMdCdName("芯片插卡");
				}else if("07".equals(posEntrymd.substring(0, 2))){
					if("".equals(cardClass)){
						t.setPosEntryMdCdName("未知");
					}else if("0".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片非接");
					}else if("1".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片云闪付");
					}
				}else if("98".equals(posEntrymd.substring(0, 2))){
					if("".equals(cardClass)){
						t.setPosEntryMdCdName("未知");
					}else if("0".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片非接");
					}else if("1".equals(cardClass.substring(0, 1))){
						t.setPosEntryMdCdName("芯片云闪付");
					}
				}

				t.setMaTransCd(Constance.Null2EmptyTrim(obj[15]));
				
				if("1171".equals(t.getMaTransCd())||"1011".equals(t.getMaTransCd())||"4011".equals(t.getMaTransCd())||"2011".equals(t.getMaTransCd())||
				   "1161".equals(t.getMaTransCd())||"1191".equals(t.getMaTransCd())||"1261".equals(t.getMaTransCd())||"1291".equals(t.getMaTransCd())||
				   "1361".equals(t.getMaTransCd())||"1391".equals(t.getMaTransCd())||"1461".equals(t.getMaTransCd())||"1491".equals(t.getMaTransCd())||
				   "1461".equals(t.getMaTransCd())||"1491".equals(t.getMaTransCd())||"1561".equals(t.getMaTransCd())||"1591".equals(t.getMaTransCd())||
				   "1661".equals(t.getMaTransCd())||"1691".equals(t.getMaTransCd())){
					String rs = Utils.dealTransSt(t.getMaTransCd(),t.getTransSt());
					t.setDealRs(rs);
				}
				
				t.setKeyRsp(Constance.Null2EmptyTrim(obj[16]));
				
				if(("1171".equals(t.getMaTransCd())||"1011".equals(t.getMaTransCd())||"1191".equals(t.getMaTransCd())||"1391".equals(t.getMaTransCd())||"1491".equals(t.getMaTransCd())
						||"1591".equals(t.getMaTransCd())||"1291".equals(t.getMaTransCd())||"1691".equals(t.getMaTransCd())) && "1000000000".equals(t.getTransSt()) && "00".equals(t.getRespCd())){
					totalAmt = totalAmt.add(new BigDecimal(t.getTransAt()));
					totalCount++;
				}
				
				if("2011".equals(t.getMaTransCd()) && "1000000000".equals(t.getTransSt()) && "00".equals(t.getRespCd())){
					cxTotalAmt = cxTotalAmt.add(new BigDecimal(t.getTransAt()));
					cxTotalCount++;
				}
				
				tftList.add(t);
			}
		}
		
		resMap.put("totalAmt", totalAmt.toPlainString());
		resMap.put("totalCount", String.valueOf(totalCount));
		resMap.put("cxTotalAmt", cxTotalAmt.toPlainString());
		resMap.put("cxTotalCount", String.valueOf(cxTotalCount));
		
		} catch (Exception e) {
			logger.error("交易查询导出List解析异常",e);
			throw new RuntimeException("交易查询导出List解析异常");
		}
		
		return resMap;
	}
	
	
	/*private void dealWidth(List<Estrnlog> mList,List<Object> qList){
	    Operators logingMerchant=(Operators)getSession().getAttribute(Constant.SESSION_LOGIN_MERCHANT);
	    Map<String, String> transTypes=ConfigProperties.getTransTypes();
	    
		if(qList!=null&&qList.size()>0){
			Iterator iterator=qList.iterator();
			while (iterator.hasNext()) {
				Object[] obj= (Object[])iterator.next();
				Estrnlog estrn=new Estrnlog(); 
				if(Constance.OPERATORS_FLAG_OEM.equals(logingMerchant.getFlag())&&!Role.O_MANAGER.getCode().equals(logingMerchant.getRoleType())){
					
				 estrn.setAccount(Utils.dealCardNo(Constance.Null2EmptyTrim(obj[0])));
				
				}else{
					 estrn.setAccount(Constance.Null2EmptyTrim(obj[0]));
						
				}
				
				//卡BIN
				List<Object> cardBinList = ConfigProperties.getCardBin();
				for (int i = 0; i < cardBinList.size(); i++) {
					Object[] objs=(Object[]) cardBinList.get(i);
					if(Constance.Null2EmptyTrim(obj[0]) != null && Constance.Null2EmptyTrim(obj[0]) != ""){
						
						for (int j = 10; j >=2; j--) {
							if(Constance.Null2EmptyTrim(objs[0]).equals(Constance.Null2EmptyTrim(obj[0]).substring(0, j))){
								estrn.setCardName(Constance.Null2EmptyTrim(objs[1]));
								estrn.setBankName(Constance.Null2EmptyTrim(objs[2]));
								break;
							}
						}

					}
				}
				
				
				estrn.setEtstranCode(transTypes.get(Constance.Null2EmptyTrim(obj[1])));
				estrn.setAmount(Constance.Null2EmptyTrim(obj[2]));
				estrn.setMerName(Constance.Null2EmptyTrim(obj[3]));//商户名称
				estrn.setEtsterMid(Constance.Null2EmptyTrim(obj[4]));
				estrn.setEtsDate(Constance.Null2EmptyTrim(obj[6]));
				estrn.setEtsTime(Constance.Null2EmptyTrim(obj[5]));
				estrn.setEtstrace(Constance.Null2EmptyTrim(obj[7]));
				if(Constance.OPERATORS_FLAG_OEM.equals(logingMerchant.getFlag())&&!Role.O_MANAGER.getCode().equals(logingMerchant.getRoleType())){
					estrn.setRespCode(Utils.dealRespCodeName(respMap.get(Constance.Null2EmptyTrim(obj[8]))));
				}else{
					estrn.setRespCode(Utils.dealRespCodeName(Constance.Null2EmptyTrim(obj[8]),allRespMap));
				}
				
				
				estrn.setReversal(reversalMap.get(Constance.Null2EmptyTrim(obj[9])));   //状态
				estrn.setCardbankId(Constance.Null2EmptyTrim(obj[10]));
				estrn.setPosconoCode(Constance.Null2EmptyTrim(obj[11]));
				estrn.setOrgdate(Constance.Null2EmptyTrim(obj[12]));
				estrn.setMerNo(Constance.Null2EmptyTrim(obj[13]));
				estrn.setTermtrace(Constance.Null2EmptyTrim(obj[15]));
				estrn.setPeriod(Constance.Null2EmptyTrim(obj[14]));
				mList.add(estrn);
			}
		}
	}*/
	
	public String getExcelName() {
		String excelName="交易详情"+Constance.formateDate();
		 
			try {
				excelName = new String(excelName.getBytes(),"ISO8859-1");
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
				logger.info("生成excel名称失败了！");
			}
		 
		return  excelName;
		
	}

	@Override
	protected String getInitPageSize() {
		// TODO Auto-generated method stub
		return Constance.PAGE_MAX_SIZE+"";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.PaginationBaseAction#getSearchConditionFromSession()
	 */
	@Override
	protected BaseSearchCondition getSearchConditionFromSession() {
		// TODO Auto-generated method stub
		return (EstrnInfoSearchCondition)getSession().getAttribute(SEARCH_SESSION_BEAN_ESTRN_LOG_YJ);
	}

	/* (non-Javadoc)
	 * @see com.roc.page.PaginationBaseAction#getSearchConditionFromSubClass()
	 */
	@Override
	protected BaseSearchCondition getSearchConditionFromSubClass()
			throws Exception {
		// TODO Auto-generated method stub
		return searchCondition;
	}

	/* (non-Javadoc)
	 * @see com.roc.page.PaginationBaseAction#setSearchConditionToSubClass(com.roc.page.BaseSearchCondition)
	 */
	@Override
	protected void setSearchConditionToSubClass(
			BaseSearchCondition searchCondition) throws Exception {
		this.setSearchConditionToSubClass(searchCondition);
	}

	/* (non-Javadoc)
	 * @see com.roc.page.PaginationBaseAction#setSearchToConditionSession(com.roc.page.BaseSearchCondition)
	 */
	@Override
	protected void setSearchToConditionSession(
			BaseSearchCondition searchCondition) {
		getSession().setAttribute(SEARCH_SESSION_BEAN_ESTRN_LOG_YJ, searchCondition);
	}

	public EstrnInfoSearchCondition getSearchCondition() {
		return searchCondition;
	}

	public void setSearchCondition(EstrnInfoSearchCondition searchCondition) {
		this.searchCondition = searchCondition;
	}

	public InputStream getExcelFile() {
		return excelFile;
	}

	public void setExcelFile(InputStream excelFile) {
		this.excelFile = excelFile;
	}



}
